#include "ulib.h"

#define MAX_PROC 10
#define MAX_PIPE (MAX_PROC -1)
#define MY_PIPE_R(x) (x*2)
#define MY_PIPE_W(x) (x*2+1)
#define MAX_CMDSZ 128
#define MAX_NAMESZ 16
char cmd[MAX_CMDSZ];
int pipes[MAX_PIPE*2];
char token [MAX_CMDSZ][MAX_NAMESZ];



int
main () {
    int i, r, c;
    while (1) {
        bzero (cmd, sizeof (cmd));
        r = read (0, cmd, MAX_CMDSZ);
        cmd[r] = 0;
        c = parse_cmd (token,  cmd);
        for (i = 0; i < c; i++) {
            if (token[i][0] == '|'); //
            if (token[i][0] == '<');
            // cat < file1 | grep hello > file2

        }
    }
}

int
parse_cmd (char (*cmd_parsebuf)[MAX_NAMESZ], char * cmd) {

}

void
catfile_r (int i, char * name) {
    
}

void
catfile_w (int i, char * name) {

}

void
catpipe_r (int i) {
    close (0);
    dup (pipes[MY_PIPE_R(i)]);
}

void
catpipe_w (int i) {
    close (1);
    dup (pipes[MY_PIPE_W(i)]);
}